
return function (popen_arg)
  local socket = require'socket'

  local port = 1
  local i =0
  local sock,err
  repeat
    port = port+i
    sock,err = socket.bind('*', port)
    i = i + 1
  until sock

  sock:settimeout(0)
  sock:accept()
  local file = io.popen(popen_arg .. ' '..port,'w')
  socket.select({sock})
  local c = assert(sock:accept())

  while true do
    local str = io.read()
    c:send(str..'\n')
    if str == 'exit' then
      break
    end
  end
end

